function SuperType(name) {
  this.name = name;
  this.colors = ["red", "blue", "green"];
}

SuperType.prototype.sayName = function () {
  console.log(this.name);
}

function SubType(name, age) {
  // 继承属性
  SuperType.call(this, name);
  // 添加属性
  this.age = age;
}

// 继承方法
SubType.prototype = new SuperType();
// 添加方法
SubType.prototype.sayAge = function () {
  console.log(this.age);
}

let instance = new SubType('holo', 22);
instance.colors.push('black');
console.log(instance.colors);
console.log(instance.name);

let instance2 = new SubType('holo2', 10);
console.log(instance2.colors);
console.log(instance2.name);


console.log('---------------------------------');
// 寄生式组合继承
function inheritPrototype(subType, superType) {
  let prototype = Object(superType.prototype); // 创建对象
  prototype.constructor = subType;  // 增强对象
  subType.prototype = prototype;  // 赋值对象
}

function SuperType(name) {
  this.name = name;
  this.colors = ['red', 'blue', 'green'];
}

SuperType.prototype.sayName = function () {
  console.log(this.name);
};

function SubType(name, age) {
  SuperType.call(this, name);
  this.age = age;
}
inheritPrototype(SubType, SuperType);

SubType.prototype.sayAge = function () {
  console.log(this.age);
}

let instance3 = new SubType('holo3', 20)
instance3.sayName()
